package com.shanshi.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.google.gson.Gson;
import com.shanshi.activity.tool.OkHttpTool;
import com.shanshi.activity.tool.PhoneNum;


public class PhoneNumberCheckActivity extends AppCompatActivity {
    private Button sure;
    private EditText et_num;
    private CheckBox cb_check;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    private CheckBox checkBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_number_check);
        sure= (Button) findViewById(R.id.login_sure);
        et_num= (EditText) findViewById(R.id.tel);
        cb_check= (CheckBox) findViewById(R.id.check);
        sharedPreferences =this.getSharedPreferences("share",MODE_PRIVATE);
        editor = sharedPreferences.edit();
        checkBox = (CheckBox) findViewById(R.id.check);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkBox.isChecked()){
                    sure.setEnabled(true);
                    sure.setBackgroundResource(R.drawable.button_style);
                }else {
                    sure.setEnabled(false);
                    sure.setBackgroundResource(R.drawable.button_style3);
                }
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (PhoneNum.isPhone(et_num.toString())){
                    OkHttpTool.doGet("http://192.168.31.248:8080/SsProject/app/auditPhoneNum?phoneNum=" + et_num.toString(), new OkHttpTool.setOkhttpListener() {
                        @Override
                        public void onSuccess(String s) {
                            Gson gson=new Gson();
                            Log.e("=====num", "onSuccess: "+s );
                            //editor.putString("userId",)
                        }

                        @Override
                        public void onFail() {

                        }
                    });
                }
            }
        });
    }
}
